<!DOCTYPE html>
<html lang="zh-Hans">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.3/css/all.min.css" integrity="sha256-2H3fkXt6FEmrReK448mDVGKb3WW2ZZw35gI7vqHOE4Y=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{&quot;hostname&quot;:&quot;www.nilstorm.com&quot;,&quot;root&quot;:&quot;&#x2F;&quot;,&quot;images&quot;:&quot;&#x2F;images&quot;,&quot;scheme&quot;:&quot;Gemini&quot;,&quot;version&quot;:&quot;8.5.0&quot;,&quot;exturl&quot;:false,&quot;sidebar&quot;:{&quot;position&quot;:&quot;left&quot;,&quot;display&quot;:&quot;post&quot;,&quot;padding&quot;:18,&quot;offset&quot;:12},&quot;copycode&quot;:false,&quot;bookmark&quot;:{&quot;enable&quot;:false,&quot;color&quot;:&quot;#222&quot;,&quot;save&quot;:&quot;auto&quot;},&quot;fancybox&quot;:false,&quot;mediumzoom&quot;:false,&quot;lazyload&quot;:false,&quot;pangu&quot;:false,&quot;comments&quot;:{&quot;style&quot;:&quot;tabs&quot;,&quot;active&quot;:null,&quot;storage&quot;:true,&quot;lazyload&quot;:false,&quot;nav&quot;:null},&quot;motion&quot;:{&quot;enable&quot;:true,&quot;async&quot;:false,&quot;transition&quot;:{&quot;post_block&quot;:&quot;fadeIn&quot;,&quot;post_header&quot;:&quot;fadeInDown&quot;,&quot;post_body&quot;:&quot;fadeInDown&quot;,&quot;coll_header&quot;:&quot;fadeInLeft&quot;,&quot;sidebar&quot;:&quot;fadeInUp&quot;}},&quot;prism&quot;:false,&quot;i18n&quot;:{&quot;placeholder&quot;:&quot;Searching...&quot;,&quot;empty&quot;:&quot;We didn&#39;t find any results for the search: ${query}&quot;,&quot;hits_time&quot;:&quot;${hits} results found in ${time} ms&quot;,&quot;hits&quot;:&quot;${hits} results found&quot;}}</script><script src="/js/config.js"></script>
<meta name="description" content="NM_SAME_SIMPLE_NAME_AS_SUPERCLASS 翻译The class name … shadows the simple name of the superclass …This class has a simple name that is identical to that of its superclass, except that its superclass is">
<meta property="og:type" content="article">
<meta property="og:title" content="FindBugs 规则整理：Bad Practice">
<meta property="og:url" content="http://www.nilstorm.com/2017/f6c077f9.html">
<meta property="og:site_name" content="Lam&#39;s Blog">
<meta property="og:description" content="NM_SAME_SIMPLE_NAME_AS_SUPERCLASS 翻译The class name … shadows the simple name of the superclass …This class has a simple name that is identical to that of its superclass, except that its superclass is">
<meta property="og:locale">
<meta property="og:image" content="https://tva1.sinaimg.cn/large/007S8ZIlgy1gee6wkfo69j30e9026gm4.jpg">
<meta property="article:published_time" content="2017-03-03T02:36:27.000Z">
<meta property="article:modified_time" content="2021-06-06T08:08:18.169Z">
<meta property="article:author" content="LinBinghe">
<meta property="article:tag" content="FindBugs">
<meta property="article:tag" content="规则">
<meta property="article:tag" content="Bad Practice">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://tva1.sinaimg.cn/large/007S8ZIlgy1gee6wkfo69j30e9026gm4.jpg">


<link rel="canonical" href="http://www.nilstorm.com/2017/f6c077f9.html">



<script class="next-config" data-name="page" type="application/json">{&quot;sidebar&quot;:&quot;&quot;,&quot;isHome&quot;:false,&quot;isPost&quot;:true,&quot;lang&quot;:&quot;zh-Hans&quot;,&quot;comments&quot;:true,&quot;permalink&quot;:&quot;http:&#x2F;&#x2F;www.nilstorm.com&#x2F;2017&#x2F;f6c077f9.html&quot;,&quot;path&quot;:&quot;2017&#x2F;f6c077f9.html&quot;,&quot;title&quot;:&quot;FindBugs 规则整理：Bad Practice&quot;}</script>

<script class="next-config" data-name="calendar" type="application/json">&quot;&quot;</script>
<title>FindBugs 规则整理：Bad Practice | Lam's Blog</title>
  




  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
<link rel="alternate" href="/atom.xml" title="Lam's Blog" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="Toggle navigation bar" role="button">
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <h1 class="site-title">Lam's Blog</h1>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">Knowledge as Action</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>







</div>
        
  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          Table of Contents
        </li>
        <li class="sidebar-nav-overview">
          Overview
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#NM-SAME-SIMPLE-NAME-AS-SUPERCLASS"><span class="nav-number">1.</span> <span class="nav-text">NM_SAME_SIMPLE_NAME_AS_SUPERCLASS</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#ES-COMPARING-STRINGS-WITH-EQ"><span class="nav-number">2.</span> <span class="nav-text">ES_COMPARING_STRINGS_WITH_EQ</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#SE-BAD-FIELD"><span class="nav-number">3.</span> <span class="nav-text">SE_BAD_FIELD</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#AM-CREATES-EMPTY-JAR-FILE-ENTRY"><span class="nav-number">4.</span> <span class="nav-text">AM_CREATES_EMPTY_JAR_FILE_ENTRY</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#AM-CREATES-EMPTY-ZIP-FILE-ENTRY"><span class="nav-number">5.</span> <span class="nav-text">AM_CREATES_EMPTY_ZIP_FILE_ENTRY</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#BC-EQUALS-METHOD-SHOULD-WORK-FOR-ALL-OBJECTS"><span class="nav-number">6.</span> <span class="nav-text">BC_EQUALS_METHOD_SHOULD_WORK_FOR_ALL_OBJECTS</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#DMI-RANDOM-USED-ONLY-ONCE"><span class="nav-number">7.</span> <span class="nav-text">DMI_RANDOM_USED_ONLY_ONCE</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#BIT-SIGNED-CHECK"><span class="nav-number">8.</span> <span class="nav-text">BIT_SIGNED_CHECK</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#CN-IDIOM"><span class="nav-number">9.</span> <span class="nav-text">CN_IDIOM</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#CN-IDIOM-NO-SUPER-CALL"><span class="nav-number">10.</span> <span class="nav-text">CN_IDIOM_NO_SUPER_CALL</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#CN-IMPLEMENTS-CLONE-BUT-NOT-CLONEABLE"><span class="nav-number">11.</span> <span class="nav-text">CN_IMPLEMENTS_CLONE_BUT_NOT_CLONEABLE</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#CO-ABSTRACT-SELF"><span class="nav-number">12.</span> <span class="nav-text">CO_ABSTRACT_SELF</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#CO-SELF-NO-OBJECT"><span class="nav-number">13.</span> <span class="nav-text">CO_SELF_NO_OBJECT</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#DE-MIGHT-DROP"><span class="nav-number">14.</span> <span class="nav-text">DE_MIGHT_DROP</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#DE-MIGHT-IGNORE"><span class="nav-number">15.</span> <span class="nav-text">DE_MIGHT_IGNORE</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#DMI-USING-REMOVEALL-TO-CLEAR-COLLECTION"><span class="nav-number">16.</span> <span class="nav-text">DMI_USING_REMOVEALL_TO_CLEAR_COLLECTION</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#DP-CREATE-CLASSLOADER-INSIDE-DO-PRIVILEGED"><span class="nav-number">17.</span> <span class="nav-text">DP_CREATE_CLASSLOADER_INSIDE_DO_PRIVILEGED</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#DM-EXIT"><span class="nav-number">18.</span> <span class="nav-text">DM_EXIT</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#DM-RUN-FINALIZERS-ON-EXIT"><span class="nav-number">19.</span> <span class="nav-text">DM_RUN_FINALIZERS_ON_EXIT</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#ES-COMPARING-PARAMETER-STRING-WITH-EQ"><span class="nav-number">20.</span> <span class="nav-text">ES_COMPARING_PARAMETER_STRING_WITH_EQ</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#EQ-ABSTRACT-SELF"><span class="nav-number">21.</span> <span class="nav-text">EQ_ABSTRACT_SELF</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#EQ-CHECK-FOR-OPERAND-NOT-COMPATIBLE-WITH-THIS"><span class="nav-number">22.</span> <span class="nav-text">EQ_CHECK_FOR_OPERAND_NOT_COMPATIBLE_WITH_THIS</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#EQ-COMPARETO-USE-OBJECT-EQUALS"><span class="nav-number">23.</span> <span class="nav-text">EQ_COMPARETO_USE_OBJECT_EQUALS</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#EQ-GETCLASS-AND-CLASS-CONSTANT"><span class="nav-number">24.</span> <span class="nav-text">EQ_GETCLASS_AND_CLASS_CONSTANT</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#EQ-SELF-NO-OBJECT"><span class="nav-number">25.</span> <span class="nav-text">EQ_SELF_NO_OBJECT</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#FI-EMPTY"><span class="nav-number">26.</span> <span class="nav-text">FI_EMPTY</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#GC-UNCHECKED-TYPE-IN-GENERIC-CALL"><span class="nav-number">27.</span> <span class="nav-text">GC_UNCHECKED_TYPE_IN_GENERIC_CALL</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#HE-EQUALS-NO-HASHCODE"><span class="nav-number">28.</span> <span class="nav-text">HE_EQUALS_NO_HASHCODE</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#HE-HASHCODE-NO-EQUALS"><span class="nav-number">29.</span> <span class="nav-text">HE_HASHCODE_NO_EQUALS</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#HE-EQUALS-USE-HASHCODE"><span class="nav-number">30.</span> <span class="nav-text">HE_EQUALS_USE_HASHCODE</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#HE-INHERITS-EQUALS-USE-HASHCODE"><span class="nav-number">31.</span> <span class="nav-text">HE_INHERITS_EQUALS_USE_HASHCODE</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#IC-SUPERCLASS-USES-SUBCLASS-DURING-INITIALIZATION"><span class="nav-number">32.</span> <span class="nav-text">IC_SUPERCLASS_USES_SUBCLASS_DURING_INITIALIZATION</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#IMSE-DONT-CATCH-IMSE"><span class="nav-number">33.</span> <span class="nav-text">IMSE_DONT_CATCH_IMSE</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#ISC-INSTANTIATE-STATIC-CLASS"><span class="nav-number">34.</span> <span class="nav-text">ISC_INSTANTIATE_STATIC_CLASS</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#IT-NO-SUCH-ELEMENT"><span class="nav-number">35.</span> <span class="nav-text">IT_NO_SUCH_ELEMENT</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#J2EE-STORE-OF-NON-SERIALIZABLE-OBJECT-INTO-SESSION"><span class="nav-number">36.</span> <span class="nav-text">J2EE_STORE_OF_NON_SERIALIZABLE_OBJECT_INTO_SESSION</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#JCIP-FIELD-ISNT-FINAL-IN-IMMUTABLE-CLASS"><span class="nav-number">37.</span> <span class="nav-text">JCIP_FIELD_ISNT_FINAL_IN_IMMUTABLE_CLASS</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#NP-BOOLEAN-RETURN-NULL"><span class="nav-number">38.</span> <span class="nav-text">NP_BOOLEAN_RETURN_NULL</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#NP-EQUALS-SHOULD-HANDLE-NULL-ARGUMENT"><span class="nav-number">39.</span> <span class="nav-text">NP_EQUALS_SHOULD_HANDLE_NULL_ARGUMENT</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#NP-TOSTRING-COULD-RETURN-NULL"><span class="nav-number">40.</span> <span class="nav-text">NP_TOSTRING_COULD_RETURN_NULL</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#NM-CLASS-NAMING-CONVENTION"><span class="nav-number">41.</span> <span class="nav-text">NM_CLASS_NAMING_CONVENTION</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#NM-CLASS-NOT-EXCEPTION"><span class="nav-number">42.</span> <span class="nav-text">NM_CLASS_NOT_EXCEPTION</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#NM-CONFUSING"><span class="nav-number">43.</span> <span class="nav-text">NM_CONFUSING</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#NM-FIELD-NAMING-CONVENTION"><span class="nav-number">44.</span> <span class="nav-text">NM_FIELD_NAMING_CONVENTION</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#NM-FUTURE-KEYWORD-USED-AS-IDENTIFIER"><span class="nav-number">45.</span> <span class="nav-text">NM_FUTURE_KEYWORD_USED_AS_IDENTIFIER</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#NM-FUTURE-KEYWORD-USED-AS-MEMBER-IDENTIFIER"><span class="nav-number">46.</span> <span class="nav-text">NM_FUTURE_KEYWORD_USED_AS_MEMBER_IDENTIFIER</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#NM-METHOD-NAMING-CONVENTION"><span class="nav-number">47.</span> <span class="nav-text">NM_METHOD_NAMING_CONVENTION</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#NM-SAME-SIMPLE-NAME-AS-INTERFACE"><span class="nav-number">48.</span> <span class="nav-text">NM_SAME_SIMPLE_NAME_AS_INTERFACE</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#NM-SAME-SIMPLE-NAME-AS-SUPERCLASS-1"><span class="nav-number">49.</span> <span class="nav-text">NM_SAME_SIMPLE_NAME_AS_SUPERCLASS</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#NM-VERY-CONFUSING-INTENTIONAL"><span class="nav-number">50.</span> <span class="nav-text">NM_VERY_CONFUSING_INTENTIONAL</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#NM-WRONG-PACKAGE-INTENTIONAL"><span class="nav-number">51.</span> <span class="nav-text">NM_WRONG_PACKAGE_INTENTIONAL</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#ODR-OPEN-DATABASE-RESOURCE"><span class="nav-number">52.</span> <span class="nav-text">ODR_OPEN_DATABASE_RESOURCE</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#OS-OPEN-STREAM"><span class="nav-number">53.</span> <span class="nav-text">OS_OPEN_STREAM</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#OS-OPEN-STREAM-EXCEPTION-PATH"><span class="nav-number">54.</span> <span class="nav-text">OS_OPEN_STREAM_EXCEPTION_PATH</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#RC-REF-COMPARISON-BAD-PRACTICE"><span class="nav-number">55.</span> <span class="nav-text">RC_REF_COMPARISON_BAD_PRACTICE</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#RC-REF-COMPARISON-BAD-PRACTICE-BOOLEAN"><span class="nav-number">56.</span> <span class="nav-text">RC_REF_COMPARISON_BAD_PRACTICE_BOOLEAN</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#RR-NOT-CHECKED"><span class="nav-number">57.</span> <span class="nav-text">RR_NOT_CHECKED</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#SR-NOT-CHECKED"><span class="nav-number">58.</span> <span class="nav-text">SR_NOT_CHECKED</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#RV-RETURN-VALUE-IGNORED-BAD-PRACTICE"><span class="nav-number">59.</span> <span class="nav-text">RV_RETURN_VALUE_IGNORED_BAD_PRACTICE</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#SI-INSTANCE-BEFORE-FINALS-ASSIGNED"><span class="nav-number">60.</span> <span class="nav-text">SI_INSTANCE_BEFORE_FINALS_ASSIGNED</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#SE-BAD-FIELD-STORE"><span class="nav-number">61.</span> <span class="nav-text">SE_BAD_FIELD_STORE</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#SE-COMPARATOR-SHOULD-BE-SERIALIZABLE"><span class="nav-number">62.</span> <span class="nav-text">SE_COMPARATOR_SHOULD_BE_SERIALIZABLE</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#SE-INNER-CLASS"><span class="nav-number">63.</span> <span class="nav-text">SE_INNER_CLASS</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#SE-NONFINAL-SERIALVERSIONID"><span class="nav-number">64.</span> <span class="nav-text">SE_NONFINAL_SERIALVERSIONID</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#SE-NO-SUITABLE-CONSTRUCTOR"><span class="nav-number">65.</span> <span class="nav-text">SE_NO_SUITABLE_CONSTRUCTOR</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#SE-NO-SUITABLE-CONSTRUCTOR-FOR-EXTERNALIZATION"><span class="nav-number">66.</span> <span class="nav-text">SE_NO_SUITABLE_CONSTRUCTOR_FOR_EXTERNALIZATION</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#SE-READ-RESOLVE-MUST-RETURN-OBJECT"><span class="nav-number">67.</span> <span class="nav-text">SE_READ_RESOLVE_MUST_RETURN_OBJECT</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#SE-TRANSIENT-FIELD-NOT-RESTORED"><span class="nav-number">68.</span> <span class="nav-text">SE_TRANSIENT_FIELD_NOT_RESTORED</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#SE-NO-SERIALVERSIONID"><span class="nav-number">69.</span> <span class="nav-text">SE_NO_SERIALVERSIONID</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#UI-INHERITANCE-UNSAFE-GETRESOURCE"><span class="nav-number">70.</span> <span class="nav-text">UI_INHERITANCE_UNSAFE_GETRESOURCE</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%85%B6%E4%BB%96%E6%96%87%E7%AB%A0%EF%BC%88%E6%8C%81%E7%BB%AD%E6%9B%B4%E6%96%B0%EF%BC%89"><span class="nav-number">71.</span> <span class="nav-text">其他文章（持续更新）</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%BC%95%E7%94%A8"><span class="nav-number">72.</span> <span class="nav-text">引用</span></a></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="LinBinghe"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">LinBinghe</p>
  <div class="site-description" itemprop="description">Knowledge as Action</div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives">
          <span class="site-state-item-count">39</span>
          <span class="site-state-item-name">posts</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
        <span class="site-state-item-count">13</span>
        <span class="site-state-item-name">categories</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
        <span class="site-state-item-count">60</span>
        <span class="site-state-item-name">tags</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author site-overview-item animated">
      <span class="links-of-author-item">
        <a href="https://github.com/LinBinghe" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;LinBinghe" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i></a>
      </span>
      <span class="links-of-author-item">
        <a href="https://www.zhihu.com/people/shawn_lam" title="Zhihu → https:&#x2F;&#x2F;www.zhihu.com&#x2F;people&#x2F;shawn_lam" rel="noopener" target="_blank"><i class="fab fa-zhihu fa-fw"></i></a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:linbinghe@gmail.com" title="E-Mail → mailto:linbinghe@gmail.com" rel="noopener" target="_blank"><i class="fa fa-envelope fa-fw"></i></a>
      </span>
  </div>



        </div>
      </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top" role="button" aria-label="Back to top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-Hans">
    <link itemprop="mainEntityOfPage" href="http://www.nilstorm.com/2017/f6c077f9.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="LinBinghe">
      <meta itemprop="description" content="Knowledge as Action">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Lam's Blog">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          FindBugs 规则整理：Bad Practice
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">Posted on</span>

      <time title="Created: 2017-03-03 10:36:27" itemprop="dateCreated datePublished" datetime="2017-03-03T10:36:27+08:00">2017-03-03</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">Edited on</span>
        <time title="Modified: 2021-06-06 16:08:18" itemprop="dateModified" datetime="2021-06-06T16:08:18+08:00">2021-06-06</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">In</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/FindBugs/" itemprop="url" rel="index"><span itemprop="name">FindBugs</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <h1 id="NM-SAME-SIMPLE-NAME-AS-SUPERCLASS"><a href="#NM-SAME-SIMPLE-NAME-AS-SUPERCLASS" class="headerlink" title="NM_SAME_SIMPLE_NAME_AS_SUPERCLASS"></a>NM_SAME_SIMPLE_NAME_AS_SUPERCLASS</h1><ul>
<li>翻译<br><em>The class name … shadows the simple name of the superclass …<br>This class has a simple name that is identical to that of its superclass, except that its superclass is in a different package (e.g.,alpha.Fooextendsbeta.Foo). This can be exceptionally confusing, create lots of situations in which you have to look at import statements to resolve references and creates many opportunities to accidently define methods that do not override methods in their superclasses.</em><br>某个类的名字和父类名称一样，这将会导致混乱的情况，一旦出现问题也将难以发现。</li>
<li>原因<br>同翻译</li>
<li>解决方案<br>修改父类或者子类的名称<span id="more"></span>
</li>
</ul>
<h1 id="ES-COMPARING-STRINGS-WITH-EQ"><a href="#ES-COMPARING-STRINGS-WITH-EQ" class="headerlink" title="ES_COMPARING_STRINGS_WITH_EQ"></a>ES_COMPARING_STRINGS_WITH_EQ</h1><ul>
<li>翻译<br><em>Comparison of String objects using == or != in …<br>This code … for reference equality using the == or != operators. Unless both strings are either constants in a source file, or have been interned using the String.intern() method, the same string value may be represented by two different String objects. Consider using the equals(Object) method instead.</em><br>使用==或者!=来比较字符串对象。除非两个字符串是同一个源文件里的常量，或者使用String.intern()方法，否则两个同样值的字符串可能会被两个不一样的字符串对象持有，考虑使用equals(Object)来比较。</li>
<li>原因<br>使用==或者!=来比较字符串会比较两个字符串对象的内存地址，通常这是不一样的。</li>
<li>解决方案<br>如果是想比较值的话通过equals(Object)来比较</li>
</ul>
<h1 id="SE-BAD-FIELD"><a href="#SE-BAD-FIELD" class="headerlink" title="SE_BAD_FIELD"></a>SE_BAD_FIELD</h1><ul>
<li>翻译<br><em>Class … defines non-transient non-serializable instance field …<br>This Serializable class defines a non-primitive instance field which is neither transient, Serializable, orjava.lang.Object, and does not appear to implement the Externalizableinterface or the readObject() and writeObject() methods. Objects of this class will not be deserialized correctly if a non-Serializable object is stored in this field.</em><br>该可序列化类定义了一个非暂存也不可序列化的非原始实例字段，也没有实现Externalizable接口或者readObject() 和 writeObject()方法，所以如果非序列化对象被存储在该字段里，那么这个类的对象将无法正确将其反序列化</li>
<li>原因<br>序列化时所有的成员变量都必须递归的实现序列化，否则将导致序列化失败。如果某个成员变量不想被序列化要么标注为瞬态要么重写readObj方法</li>
<li>解决方案<br>给字段加上序列化或者瞬态关键字transient</li>
</ul>
<h1 id="AM-CREATES-EMPTY-JAR-FILE-ENTRY"><a href="#AM-CREATES-EMPTY-JAR-FILE-ENTRY" class="headerlink" title="AM_CREATES_EMPTY_JAR_FILE_ENTRY"></a>AM_CREATES_EMPTY_JAR_FILE_ENTRY</h1><p><em>Creates an empty jar file entry</em><br>调用putNextEntry()方法写入新的 jar 文件条目时立即调用closeEntry()方法。这样会造成JarFile条目为空。</p>
<h1 id="AM-CREATES-EMPTY-ZIP-FILE-ENTRY"><a href="#AM-CREATES-EMPTY-ZIP-FILE-ENTRY" class="headerlink" title="AM_CREATES_EMPTY_ZIP_FILE_ENTRY"></a>AM_CREATES_EMPTY_ZIP_FILE_ENTRY</h1><p><em>Creates an empty zip file entry</em><br>调用putNextEntry()方法写入新的 zip 文件条目时立即调用closeEntry()方法。这样会造成ZipFile条目为空。</p>
<h1 id="BC-EQUALS-METHOD-SHOULD-WORK-FOR-ALL-OBJECTS"><a href="#BC-EQUALS-METHOD-SHOULD-WORK-FOR-ALL-OBJECTS" class="headerlink" title="BC_EQUALS_METHOD_SHOULD_WORK_FOR_ALL_OBJECTS"></a>BC_EQUALS_METHOD_SHOULD_WORK_FOR_ALL_OBJECTS</h1><p><em>Equals method should not assume anything about the type of its argument</em><br>equals(Object o)方法不能对参数o的类型做任何的假设。比较此对象与指定的对象。当且仅当该参数不为 null，并且是表示与此对象相同的类型的对象时，结果才为 true。</p>
<h1 id="DMI-RANDOM-USED-ONLY-ONCE"><a href="#DMI-RANDOM-USED-ONLY-ONCE" class="headerlink" title="DMI_RANDOM_USED_ONLY_ONCE"></a>DMI_RANDOM_USED_ONLY_ONCE</h1><p><em>Random object created and used only once</em><br>随机创建对象只使用过一次就抛弃</p>
<h1 id="BIT-SIGNED-CHECK"><a href="#BIT-SIGNED-CHECK" class="headerlink" title="BIT_SIGNED_CHECK"></a>BIT_SIGNED_CHECK</h1><p><em>Check for sign of bitwise operation</em><br>检查位操作符运行是否合理</p>
<h1 id="CN-IDIOM"><a href="#CN-IDIOM" class="headerlink" title="CN_IDIOM"></a>CN_IDIOM</h1><p><em>Class implements Cloneable but does not define or use clone method</em><br>类实现了Cloneable接口，但是没有定义或使用clone方法。按照惯例，实现此接口的类应该使用公共方法重写 Object.clone（它是受保护的），以获得有关重写此方法的详细信息。</p>
<h1 id="CN-IDIOM-NO-SUPER-CALL"><a href="#CN-IDIOM-NO-SUPER-CALL" class="headerlink" title="CN_IDIOM_NO_SUPER_CALL"></a>CN_IDIOM_NO_SUPER_CALL</h1><p><em>clone method does not call super.clone()</em><br>一个非final类型的类定义了clone()方法而没有调用super.clone()方法。例如：B扩展自A，如果B中clone方法调用了spuer.clone（），而A中的clone没有调用spuer.clone()，就会造成结果类型不准确。要求A的clone方法中调用spuer.clone()方法。</p>
<h1 id="CN-IMPLEMENTS-CLONE-BUT-NOT-CLONEABLE"><a href="#CN-IMPLEMENTS-CLONE-BUT-NOT-CLONEABLE" class="headerlink" title="CN_IMPLEMENTS_CLONE_BUT_NOT_CLONEABLE"></a>CN_IMPLEMENTS_CLONE_BUT_NOT_CLONEABLE</h1><p><em>Class defines clone() but doesn’t implement Cloneable</em><br>类中定义了clone方法但是它没有实现Cloneable接口</p>
<h1 id="CO-ABSTRACT-SELF"><a href="#CO-ABSTRACT-SELF" class="headerlink" title="CO_ABSTRACT_SELF"></a>CO_ABSTRACT_SELF</h1><p><em>Abstract class defines covariant compareTo() method</em><br>抽象类中定义了多个compareTo()方法，正确的是覆写Comparable中的compareTo方法，方法的参数为Object类型</p>
<h1 id="CO-SELF-NO-OBJECT"><a href="#CO-SELF-NO-OBJECT" class="headerlink" title="CO_SELF_NO_OBJECT"></a>CO_SELF_NO_OBJECT</h1><p><em>Covariant compareTo() method defined</em><br>类中定义了多个compareTo()方法，正确的是覆写Comparable中的compareTo方法，方法的参数为Object类型</p>
<h1 id="DE-MIGHT-DROP"><a href="#DE-MIGHT-DROP" class="headerlink" title="DE_MIGHT_DROP"></a>DE_MIGHT_DROP</h1><p><em>Method might drop exception</em><br>方法可能抛出异常</p>
<h1 id="DE-MIGHT-IGNORE"><a href="#DE-MIGHT-IGNORE" class="headerlink" title="DE_MIGHT_IGNORE"></a>DE_MIGHT_IGNORE</h1><p><em>Method might ignore exception</em><br>方法可能忽略异常</p>
<h1 id="DMI-USING-REMOVEALL-TO-CLEAR-COLLECTION"><a href="#DMI-USING-REMOVEALL-TO-CLEAR-COLLECTION" class="headerlink" title="DMI_USING_REMOVEALL_TO_CLEAR_COLLECTION"></a>DMI_USING_REMOVEALL_TO_CLEAR_COLLECTION</h1><p><em>Don’t use removeAll to clear a collection</em><br>不要用removeAll方法去clear一个集合</p>
<h1 id="DP-CREATE-CLASSLOADER-INSIDE-DO-PRIVILEGED"><a href="#DP-CREATE-CLASSLOADER-INSIDE-DO-PRIVILEGED" class="headerlink" title="DP_CREATE_CLASSLOADER_INSIDE_DO_PRIVILEGED"></a>DP_CREATE_CLASSLOADER_INSIDE_DO_PRIVILEGED</h1><p><em>Classloaders should only be created inside doPrivileged block</em><br>类加载器只能建立在特殊的方法体内</p>
<h1 id="DM-EXIT"><a href="#DM-EXIT" class="headerlink" title="DM_EXIT"></a>DM_EXIT</h1><p><em>Method invokes System.exit(…)</em><br>在方法中调用System.exit(…)语句，考虑用RuntimeException来代替</p>
<h1 id="DM-RUN-FINALIZERS-ON-EXIT"><a href="#DM-RUN-FINALIZERS-ON-EXIT" class="headerlink" title="DM_RUN_FINALIZERS_ON_EXIT"></a>DM_RUN_FINALIZERS_ON_EXIT</h1><p><em>Method invokes dangerous method runFinalizersOnExit</em><br>在方法中调用了System.runFinalizersOnExit 或者Runtime.runFinalizersOnExit方法，因为这样做是很危险的。</p>
<h1 id="ES-COMPARING-PARAMETER-STRING-WITH-EQ"><a href="#ES-COMPARING-PARAMETER-STRING-WITH-EQ" class="headerlink" title="ES_COMPARING_PARAMETER_STRING_WITH_EQ"></a>ES_COMPARING_PARAMETER_STRING_WITH_EQ</h1><p><em>Comparison of String parameter using == or !=</em><br>用==或者!=方法去比较String类型的参数</p>
<h1 id="EQ-ABSTRACT-SELF"><a href="#EQ-ABSTRACT-SELF" class="headerlink" title="EQ_ABSTRACT_SELF"></a>EQ_ABSTRACT_SELF</h1><p><em>Abstract class defines covariant equals() method</em><br>抽象类定义了共变的compareTo()方法</p>
<h1 id="EQ-CHECK-FOR-OPERAND-NOT-COMPATIBLE-WITH-THIS"><a href="#EQ-CHECK-FOR-OPERAND-NOT-COMPATIBLE-WITH-THIS" class="headerlink" title="EQ_CHECK_FOR_OPERAND_NOT_COMPATIBLE_WITH_THIS"></a>EQ_CHECK_FOR_OPERAND_NOT_COMPATIBLE_WITH_THIS</h1><p><em>Equals checks for noncompatible operand</em><br>equals方法检查不一致的操作。两个类根本就是父子关系而去调用equals方法去判读对象是否相等。</p>
<h1 id="EQ-COMPARETO-USE-OBJECT-EQUALS"><a href="#EQ-COMPARETO-USE-OBJECT-EQUALS" class="headerlink" title="EQ_COMPARETO_USE_OBJECT_EQUALS"></a>EQ_COMPARETO_USE_OBJECT_EQUALS</h1><p><em>Class defines compareTo(…) and uses Object.equals()</em><br>类定义了compareTo(…)方法，却使用Object.equals()方法</p>
<h1 id="EQ-GETCLASS-AND-CLASS-CONSTANT"><a href="#EQ-GETCLASS-AND-CLASS-CONSTANT" class="headerlink" title="EQ_GETCLASS_AND_CLASS_CONSTANT"></a>EQ_GETCLASS_AND_CLASS_CONSTANT</h1><p><em>equals method fails for subtypes</em><br>类中的equals方法可能被子类中的方法所破坏，当使用类似于Foo.class == o.getClass()的判断时考虑用this.getClass() == o.getClass()来替换</p>
<h1 id="EQ-SELF-NO-OBJECT"><a href="#EQ-SELF-NO-OBJECT" class="headerlink" title="EQ_SELF_NO_OBJECT"></a>EQ_SELF_NO_OBJECT</h1><p><em>Covariant equals() method defined</em><br>类中定义了多个equals方法。正确的做法是覆写Object中的equals方法，它的参数为Object类型的对象。</p>
<h1 id="FI-EMPTY"><a href="#FI-EMPTY" class="headerlink" title="FI_EMPTY"></a>FI_EMPTY</h1><p><em>Empty finalizer should be deleted</em><br>应当删除空的finalize()方法</p>
<h1 id="GC-UNCHECKED-TYPE-IN-GENERIC-CALL"><a href="#GC-UNCHECKED-TYPE-IN-GENERIC-CALL" class="headerlink" title="GC_UNCHECKED_TYPE_IN_GENERIC_CALL"></a>GC_UNCHECKED_TYPE_IN_GENERIC_CALL</h1><p><em>Unchecked type in generic call</em><br>泛型调用中使用了未检查的类型</p>
<h1 id="HE-EQUALS-NO-HASHCODE"><a href="#HE-EQUALS-NO-HASHCODE" class="headerlink" title="HE_EQUALS_NO_HASHCODE"></a>HE_EQUALS_NO_HASHCODE</h1><p><em>Class defines equals() but not hashCode()</em><br>方法定义了equals方法却没有定义hashCode方法</p>
<h1 id="HE-HASHCODE-NO-EQUALS"><a href="#HE-HASHCODE-NO-EQUALS" class="headerlink" title="HE_HASHCODE_NO_EQUALS"></a>HE_HASHCODE_NO_EQUALS</h1><p><em>Class defines hashCode() but not equals()</em><br>类定义了hashCode方法去没有定义equal方法</p>
<h1 id="HE-EQUALS-USE-HASHCODE"><a href="#HE-EQUALS-USE-HASHCODE" class="headerlink" title="HE_EQUALS_USE_HASHCODE"></a>HE_EQUALS_USE_HASHCODE</h1><p><em>Class defines equals() and uses Object.hashCode()</em><br>一个类覆写了equals方法，没有覆写hashCode方法，使用了Object对象的hashCode方法</p>
<h1 id="HE-INHERITS-EQUALS-USE-HASHCODE"><a href="#HE-INHERITS-EQUALS-USE-HASHCODE" class="headerlink" title="HE_INHERITS_EQUALS_USE_HASHCODE"></a>HE_INHERITS_EQUALS_USE_HASHCODE</h1><p><em>Class inherits equals() and uses Object.hashCode()</em><br>子类继承了父类的equals方法却使用了Object的hashCode方法</p>
<h1 id="IC-SUPERCLASS-USES-SUBCLASS-DURING-INITIALIZATION"><a href="#IC-SUPERCLASS-USES-SUBCLASS-DURING-INITIALIZATION" class="headerlink" title="IC_SUPERCLASS_USES_SUBCLASS_DURING_INITIALIZATION"></a>IC_SUPERCLASS_USES_SUBCLASS_DURING_INITIALIZATION</h1><p><em>Superclass uses subclass during initialization</em><br>子类在父类未初始化之前使用父类对象实例</p>
<h1 id="IMSE-DONT-CATCH-IMSE"><a href="#IMSE-DONT-CATCH-IMSE" class="headerlink" title="IMSE_DONT_CATCH_IMSE"></a>IMSE_DONT_CATCH_IMSE</h1><p><em>Dubious catching of IllegalMonitorStateException</em><br>可疑的IllegalMonitorStateException异常捕捉</p>
<h1 id="ISC-INSTANTIATE-STATIC-CLASS"><a href="#ISC-INSTANTIATE-STATIC-CLASS" class="headerlink" title="ISC_INSTANTIATE_STATIC_CLASS"></a>ISC_INSTANTIATE_STATIC_CLASS</h1><p><em>Needless instantiation of class that only supplies static methods</em><br>为使用静态方法而创建一个实例对象。调用静态方法时只需要使用类名+静态方法名就可以了。</p>
<h1 id="IT-NO-SUCH-ELEMENT"><a href="#IT-NO-SUCH-ELEMENT" class="headerlink" title="IT_NO_SUCH_ELEMENT"></a>IT_NO_SUCH_ELEMENT</h1><p><em>Iterator next() method can’t throw NoSuchElementException</em><br>迭代器的next方法不能够抛出NoSuchElementException</p>
<h1 id="J2EE-STORE-OF-NON-SERIALIZABLE-OBJECT-INTO-SESSION"><a href="#J2EE-STORE-OF-NON-SERIALIZABLE-OBJECT-INTO-SESSION" class="headerlink" title="J2EE_STORE_OF_NON_SERIALIZABLE_OBJECT_INTO_SESSION"></a>J2EE_STORE_OF_NON_SERIALIZABLE_OBJECT_INTO_SESSION</h1><p><em>Store of non serializable object into HttpSession</em><br>在HttpSession对象中保存非连续的对象</p>
<h1 id="JCIP-FIELD-ISNT-FINAL-IN-IMMUTABLE-CLASS"><a href="#JCIP-FIELD-ISNT-FINAL-IN-IMMUTABLE-CLASS" class="headerlink" title="JCIP_FIELD_ISNT_FINAL_IN_IMMUTABLE_CLASS"></a>JCIP_FIELD_ISNT_FINAL_IN_IMMUTABLE_CLASS</h1><p><em>Fields of immutable classes should be final</em><br>不可变类的字段应当是final的</p>
<h1 id="NP-BOOLEAN-RETURN-NULL"><a href="#NP-BOOLEAN-RETURN-NULL" class="headerlink" title="NP_BOOLEAN_RETURN_NULL"></a>NP_BOOLEAN_RETURN_NULL</h1><p><em>Method with Boolean return type returns explicit null</em><br>返回值为boolean类型的方法直接返回null，这样会导致空指针异常</p>
<h1 id="NP-EQUALS-SHOULD-HANDLE-NULL-ARGUMENT"><a href="#NP-EQUALS-SHOULD-HANDLE-NULL-ARGUMENT" class="headerlink" title="NP_EQUALS_SHOULD_HANDLE_NULL_ARGUMENT"></a>NP_EQUALS_SHOULD_HANDLE_NULL_ARGUMENT</h1><p><em>equals() method does not check for null argument</em><br>变量调用equals方法时没有进行是否为null的判断</p>
<h1 id="NP-TOSTRING-COULD-RETURN-NULL"><a href="#NP-TOSTRING-COULD-RETURN-NULL" class="headerlink" title="NP_TOSTRING_COULD_RETURN_NULL"></a>NP_TOSTRING_COULD_RETURN_NULL</h1><p><em>toString method may return null</em><br>toString方法可能返回null</p>
<h1 id="NM-CLASS-NAMING-CONVENTION"><a href="#NM-CLASS-NAMING-CONVENTION" class="headerlink" title="NM_CLASS_NAMING_CONVENTION"></a>NM_CLASS_NAMING_CONVENTION</h1><p><em>Class names should start with an upper case letter</em><br>类的名称以大写字母名称开头</p>
<h1 id="NM-CLASS-NOT-EXCEPTION"><a href="#NM-CLASS-NOT-EXCEPTION" class="headerlink" title="NM_CLASS_NOT_EXCEPTION"></a>NM_CLASS_NOT_EXCEPTION</h1><p><em>Class is not derived from an Exception, even though it is named as such</em><br>类的名称中含有Exception但是却不是一个异常类的子类，这种名称会造成混淆</p>
<h1 id="NM-CONFUSING"><a href="#NM-CONFUSING" class="headerlink" title="NM_CONFUSING"></a>NM_CONFUSING</h1><p><em>Confusing method names</em><br>令人迷惑的方法命名</p>
<h1 id="NM-FIELD-NAMING-CONVENTION"><a href="#NM-FIELD-NAMING-CONVENTION" class="headerlink" title="NM_FIELD_NAMING_CONVENTION"></a>NM_FIELD_NAMING_CONVENTION</h1><p><em>Field names should start with a lower case letter</em><br>非final类型的字段需要遵循驼峰命名原则</p>
<h1 id="NM-FUTURE-KEYWORD-USED-AS-IDENTIFIER"><a href="#NM-FUTURE-KEYWORD-USED-AS-IDENTIFIER" class="headerlink" title="NM_FUTURE_KEYWORD_USED_AS_IDENTIFIER"></a>NM_FUTURE_KEYWORD_USED_AS_IDENTIFIER</h1><p><em>Use of identifier that is a keyword in later versions of Java</em><br>验证是否是java预留关键字</p>
<h1 id="NM-FUTURE-KEYWORD-USED-AS-MEMBER-IDENTIFIER"><a href="#NM-FUTURE-KEYWORD-USED-AS-MEMBER-IDENTIFIER" class="headerlink" title="NM_FUTURE_KEYWORD_USED_AS_MEMBER_IDENTIFIER"></a>NM_FUTURE_KEYWORD_USED_AS_MEMBER_IDENTIFIER</h1><p><em>Use of identifier that is a keyword in later versions of Java</em><br>验证是否时java中的关键字</p>
<h1 id="NM-METHOD-NAMING-CONVENTION"><a href="#NM-METHOD-NAMING-CONVENTION" class="headerlink" title="NM_METHOD_NAMING_CONVENTION"></a>NM_METHOD_NAMING_CONVENTION</h1><p><em>Method names should start with a lower case letter</em><br>方法名称以小写字母开头</p>
<h1 id="NM-SAME-SIMPLE-NAME-AS-INTERFACE"><a href="#NM-SAME-SIMPLE-NAME-AS-INTERFACE" class="headerlink" title="NM_SAME_SIMPLE_NAME_AS_INTERFACE"></a>NM_SAME_SIMPLE_NAME_AS_INTERFACE</h1><p><em>Class names shouldn’t shadow simple name of implemented interface</em><br>实现同一接口实现类不能使用相同的名称，即使它们位于不同的包中</p>
<h1 id="NM-SAME-SIMPLE-NAME-AS-SUPERCLASS-1"><a href="#NM-SAME-SIMPLE-NAME-AS-SUPERCLASS-1" class="headerlink" title="NM_SAME_SIMPLE_NAME_AS_SUPERCLASS"></a>NM_SAME_SIMPLE_NAME_AS_SUPERCLASS</h1><p><em>Class names shouldn’t shadow simple name of superclass</em><br>继承同一父类的子类不能使用相同的名称，即使它们位于不同的包中</p>
<h1 id="NM-VERY-CONFUSING-INTENTIONAL"><a href="#NM-VERY-CONFUSING-INTENTIONAL" class="headerlink" title="NM_VERY_CONFUSING_INTENTIONAL"></a>NM_VERY_CONFUSING_INTENTIONAL</h1><p><em>Very confusing method names (but perhaps intentional)</em><br>很容易混淆的方法命名，例如方法的名称使用大小写来区别两个不同的方法。</p>
<h1 id="NM-WRONG-PACKAGE-INTENTIONAL"><a href="#NM-WRONG-PACKAGE-INTENTIONAL" class="headerlink" title="NM_WRONG_PACKAGE_INTENTIONAL"></a>NM_WRONG_PACKAGE_INTENTIONAL</h1><p><em>Method doesn’t override method in superclass due to wrong package for parameter</em><br>由于错误引用了不同包中相同类名的对象而不能够正确的覆写父类中的方法</p>
<h1 id="ODR-OPEN-DATABASE-RESOURCE"><a href="#ODR-OPEN-DATABASE-RESOURCE" class="headerlink" title="ODR_OPEN_DATABASE_RESOURCE"></a>ODR_OPEN_DATABASE_RESOURCE</h1><p><em>Method may fail to close database resource</em><br>方法中可能存在关闭数据连接失败的情况</p>
<h1 id="OS-OPEN-STREAM"><a href="#OS-OPEN-STREAM" class="headerlink" title="OS_OPEN_STREAM"></a>OS_OPEN_STREAM</h1><p><em>Method may fail to close stream</em><br>方法中可能存在关闭流失败的情况</p>
<h1 id="OS-OPEN-STREAM-EXCEPTION-PATH"><a href="#OS-OPEN-STREAM-EXCEPTION-PATH" class="headerlink" title="OS_OPEN_STREAM_EXCEPTION_PATH"></a>OS_OPEN_STREAM_EXCEPTION_PATH</h1><p><em>Method may fail to close stream on exception</em><br>方法中可能存在关闭流时出现异常情况</p>
<h1 id="RC-REF-COMPARISON-BAD-PRACTICE"><a href="#RC-REF-COMPARISON-BAD-PRACTICE" class="headerlink" title="RC_REF_COMPARISON_BAD_PRACTICE"></a>RC_REF_COMPARISON_BAD_PRACTICE</h1><p><em>Suspicious reference comparison to constant</em><br>当两者为不同类型的对象时使用equals方法来比较它们的值是否相等，而不是使用==方法。例如比较的两者为java.lang.Integer, java.lang.Float</p>
<h1 id="RC-REF-COMPARISON-BAD-PRACTICE-BOOLEAN"><a href="#RC-REF-COMPARISON-BAD-PRACTICE-BOOLEAN" class="headerlink" title="RC_REF_COMPARISON_BAD_PRACTICE_BOOLEAN"></a>RC_REF_COMPARISON_BAD_PRACTICE_BOOLEAN</h1><ul>
<li>Suspicious reference comparison of Boolean values*<br>使用== 或者 !=操作符来比较两个 Boolean类型的对象，建议使用equals方法。</li>
</ul>
<h1 id="RR-NOT-CHECKED"><a href="#RR-NOT-CHECKED" class="headerlink" title="RR_NOT_CHECKED"></a>RR_NOT_CHECKED</h1><p><em>Method ignores results of InputStream.read()</em><br>InputStream.read方法忽略返回的多个字符，如果对结果没有检查就没法正确处理用户读取少量字符请求的情况。</p>
<h1 id="SR-NOT-CHECKED"><a href="#SR-NOT-CHECKED" class="headerlink" title="SR_NOT_CHECKED"></a>SR_NOT_CHECKED</h1><p><em>Method ignores results of InputStream.skip()</em><br>InputStream.skip()方法忽略返回的多个字符，如果对结果没有检查就没法正确处理用户跳过少量字符请求的情况</p>
<h1 id="RV-RETURN-VALUE-IGNORED-BAD-PRACTICE"><a href="#RV-RETURN-VALUE-IGNORED-BAD-PRACTICE" class="headerlink" title="RV_RETURN_VALUE_IGNORED_BAD_PRACTICE"></a>RV_RETURN_VALUE_IGNORED_BAD_PRACTICE</h1><p><em>Method ignores exceptional return value</em><br>方法忽略返回值的异常信息</p>
<h1 id="SI-INSTANCE-BEFORE-FINALS-ASSIGNED"><a href="#SI-INSTANCE-BEFORE-FINALS-ASSIGNED" class="headerlink" title="SI_INSTANCE_BEFORE_FINALS_ASSIGNED"></a>SI_INSTANCE_BEFORE_FINALS_ASSIGNED</h1><p><em>Static initializer creates instance before all static final fields assigned</em><br>在所有的static final字段赋值之前去使用静态初始化的方法创建一个类的实例。</p>
<h1 id="SE-BAD-FIELD-STORE"><a href="#SE-BAD-FIELD-STORE" class="headerlink" title="SE_BAD_FIELD_STORE"></a>SE_BAD_FIELD_STORE</h1><p><em>Non-serializable value stored into instance field of a serializable class</em><br>非序列化的值保存在声明为序列化的的非序列化字段中</p>
<h1 id="SE-COMPARATOR-SHOULD-BE-SERIALIZABLE"><a href="#SE-COMPARATOR-SHOULD-BE-SERIALIZABLE" class="headerlink" title="SE_COMPARATOR_SHOULD_BE_SERIALIZABLE"></a>SE_COMPARATOR_SHOULD_BE_SERIALIZABLE</h1><p><em>Comparator doesn’t implement Serializable</em><br>Comparator接口没有实现Serializable接口</p>
<h1 id="SE-INNER-CLASS"><a href="#SE-INNER-CLASS" class="headerlink" title="SE_INNER_CLASS"></a>SE_INNER_CLASS</h1><p><em>Serializable inner class</em><br>序列化内部类</p>
<h1 id="SE-NONFINAL-SERIALVERSIONID"><a href="#SE-NONFINAL-SERIALVERSIONID" class="headerlink" title="SE_NONFINAL_SERIALVERSIONID"></a>SE_NONFINAL_SERIALVERSIONID</h1><p><em>serialVersionUID isn’t final</em><br>serialVersionUID不是final的</p>
<h1 id="SE-NO-SUITABLE-CONSTRUCTOR"><a href="#SE-NO-SUITABLE-CONSTRUCTOR" class="headerlink" title="SE_NO_SUITABLE_CONSTRUCTOR"></a>SE_NO_SUITABLE_CONSTRUCTOR</h1><p><em>Class is Serializable but its superclass doesn’t define a void constructor</em><br>子类序列化时父类没有提供一个void的构造函数</p>
<h1 id="SE-NO-SUITABLE-CONSTRUCTOR-FOR-EXTERNALIZATION"><a href="#SE-NO-SUITABLE-CONSTRUCTOR-FOR-EXTERNALIZATION" class="headerlink" title="SE_NO_SUITABLE_CONSTRUCTOR_FOR_EXTERNALIZATION"></a>SE_NO_SUITABLE_CONSTRUCTOR_FOR_EXTERNALIZATION</h1><p><em>Class is Externalizable but doesn’t define a void constructor</em><br>Externalizable 实例类没有定义一个void类型的构造函数</p>
<h1 id="SE-READ-RESOLVE-MUST-RETURN-OBJECT"><a href="#SE-READ-RESOLVE-MUST-RETURN-OBJECT" class="headerlink" title="SE_READ_RESOLVE_MUST_RETURN_OBJECT"></a>SE_READ_RESOLVE_MUST_RETURN_OBJECT</h1><p><em>The readResolve method must be declared with a return type of Object.</em><br>readResolve从流中读取类的一个实例，此方法必须声明返回一个Object类型的对象</p>
<h1 id="SE-TRANSIENT-FIELD-NOT-RESTORED"><a href="#SE-TRANSIENT-FIELD-NOT-RESTORED" class="headerlink" title="SE_TRANSIENT_FIELD_NOT_RESTORED"></a>SE_TRANSIENT_FIELD_NOT_RESTORED</h1><p><em>Transient field that isn’t set by deserialization.</em><br>不需要被反序列化的字段没有声明transient</p>
<h1 id="SE-NO-SERIALVERSIONID"><a href="#SE-NO-SERIALVERSIONID" class="headerlink" title="SE_NO_SERIALVERSIONID"></a>SE_NO_SERIALVERSIONID</h1><p><em>Class is Serializable, but doesn’t define serialVersionUID</em><br>一个类实现了Serializable接口但是没有定义serialVersionUID类型的变量。序列化运行时使用一个称为 serialVersionUID 的版本号与每个可序列化类相关联，该序列号在反序列化过程中用于验证序列化对象的发送者和接收者是否为该对象加载了与序列化兼容的类。如果接收者加载的该对象的类的 serialVersionUID 与对应的发送者的类的版本号不同，则反序列化将会导致 InvalidClassException。可序列化类可以通过声明名为 “serialVersionUID” 的字段（该字段必须是静态 (static)、最终 (final) 的 long 型字段）显式声明其自己的 serialVersionUID</p>
<h1 id="UI-INHERITANCE-UNSAFE-GETRESOURCE"><a href="#UI-INHERITANCE-UNSAFE-GETRESOURCE" class="headerlink" title="UI_INHERITANCE_UNSAFE_GETRESOURCE"></a>UI_INHERITANCE_UNSAFE_GETRESOURCE</h1><p><em>Usage of GetResource may be unsafe if class is extended</em><br>当一个类被子类继承后不要使用this.getClass().getResource(…)来获取资源</p>
<h1 id="其他文章（持续更新）"><a href="#其他文章（持续更新）" class="headerlink" title="其他文章（持续更新）"></a>其他文章（持续更新）</h1><p><a target="_blank" rel="noopener" href="http://linbinghe.me/2017/b8a60a5e.html">FindBugs：简介与使用</a><br><a target="_blank" rel="noopener" href="http://linbinghe.me/2017/b2ff5786.html">FindBugs 规则整理：CORRECTNESS</a><br><a target="_blank" rel="noopener" href="http://linbinghe.me/2017/eb74f6c5.html">FindBugs 规则整理：Style &amp; Dodgy</a><br><a target="_blank" rel="noopener" href="http://linbinghe.me/2017/7dfffed7.html">FindBugs 规则整理：Malicious Code Vulnerability</a><br><a target="_blank" rel="noopener" href="http://linbinghe.me/2017/baebe2db.html">FindBugs 规则整理：Multithreaded Correctness</a><br><a target="_blank" rel="noopener" href="http://linbinghe.me/2017/27613e18.html">FindBugs 规则整理：Security &amp; Experimental</a><br><a target="_blank" rel="noopener" href="http://linbinghe.me/2017/8a8d645f.html">FindBugs 规则整理：Performance</a><br><a target="_blank" rel="noopener" href="http://linbinghe.me/2017/7a2a5923.html">FindBugs 规则整理：Internationalization</a></p>
<h1 id="引用"><a href="#引用" class="headerlink" title="引用"></a>引用</h1><p><em>整合以下文章过程中发现部分存在翻译错误，已做修正，同时感谢以下文章作者</em><br><a target="_blank" rel="noopener" href="https://my.oschina.net/hoodlake/blog/126735">FindBugs使用备忘录</a><br><a target="_blank" rel="noopener" href="http://blog.csdn.net/jdsjlzx/article/details/21472253/">FindBugs规则整理</a><br><a target="_blank" rel="noopener" href="http://blog.csdn.net/yang1982_0907/article/details/18606171">详解FindBugs的各项检测器</a><br><a target="_blank" rel="noopener" href="https://my.oschina.net/bairrfhoinn/blog/156200">Findbugs 缺陷详解与英文代号的对照表</a></p>
<hr>
<p><strong>版权声明</strong></p>
<p><img src="https://tva1.sinaimg.cn/large/007S8ZIlgy1gee6wkfo69j30e9026gm4.jpg" alt="Creative Commons BY-NC-ND 4.0 International License"></p>
<p><a target="_blank" rel="noopener" href="http://linbinghe.me/">Lam’s Blog</a> by <a target="_blank" rel="noopener" href="http://linbinghe.me/">Binghe Lin</a> is licensed under a <a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">Creative Commons BY-NC-ND 4.0 International License</a>.<br>由<a target="_blank" rel="noopener" href="http://linbinghe.me/">林炳河</a>创作并维护的<a target="_blank" rel="noopener" href="http://linbinghe.me/">Lam’s Blog</a>采用<a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">创作共用保留署名-非商业-禁止演绎4.0国际许可证</a>。</p>
<p>本文首发于<a target="_blank" rel="noopener" href="http://linbinghe.me/">Lam’s Blog - Knowledeg as Action</a>，版权所有，侵权必究。</p>
<p>本文永久链接：<a target="_blank" rel="noopener" href="http://codinglife.me/2017/f6c077f9.html">http://codinglife.me/2017/f6c077f9.html</a></p>

    </div>

    
    
    

    <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/FindBugs/" rel="tag"># FindBugs</a>
              <a href="/tags/%E8%A7%84%E5%88%99/" rel="tag"># 规则</a>
              <a href="/tags/Bad-Practice/" rel="tag"># Bad Practice</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/2017/b2ff5786.html" rel="prev" title="FindBugs 规则整理：CORRECTNESS">
                  <i class="fa fa-chevron-left"></i> FindBugs 规则整理：CORRECTNESS
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/2017/eb74f6c5.html" rel="next" title="FindBugs 规则整理：Style & Dodgy">
                  FindBugs 规则整理：Style & Dodgy <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">LinBinghe</span>
</div>
  <div class="powered-by">Powered by <a href="https://hexo.io/" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/" rel="noopener" target="_blank">NexT.Gemini</a>
  </div>

    </div>
  </footer>

  
  <script src="https://cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script>

  






  





</body>
</html>
